package com.yc;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * @program: concurrent
 * @description: socket
 * @author: zy
 * @create: 2022-01-13 11:27
 */
public class Test4_Client {
    //Test3的客户端程序
    public static void main(String[] args) throws IOException {
        Socket s=new Socket("localhost", 10001);
        System.out.println(  "联接成功."+ s );

        //用输入流来接时间
       try(   InputStreamReader iis=new InputStreamReader( s.getInputStream() );){
            char[] chs=new char[1024];
            int length=-1;

            while(  (length=iis.read(chs, 0, chs.length))!=-1 ){
               String str=new String(      chs,0,length);
                System.out.println(str);
            }
       }catch(Exception ex){
           ex.printStackTrace();
       }
        System.out.println("客户端断开与服务器的联接");
       s.close();
    }
}
